package leetcode.median;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: $77_组合
 * Description:
 * date: 2022-02-17 21:36
 *
 * @author liyifan
 */
public class $77_Combine {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    public List<List<Integer>> combine(int n, int k) {
        backtrack(n, k, 1);
        return res;
    }

    public void backtrack(int n, int k, int startIndex){
        if (path.size() == k) {
            res.add(new ArrayList<>(path));
        }
        for (int i = startIndex;i <= n;i++) {
            path.add(i);
            backtrack(n, k, i + 1);
            path.remove(path.size() - 1);
        }
    }


}
